package kmi.droid.animatron;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Canvas;

public class ParticleManager
{
	private static List<ParticleSystemBase> particleSystems = new ArrayList<ParticleSystemBase>();

	public static void add(ParticleSystemBase psb)
	{
		particleSystems.add(psb);
	}

	public static void update(float dt)
	{
		ArrayList<ParticleSystemBase> deads = new ArrayList<ParticleSystemBase>();

		for (int i = 0; i < particleSystems.size(); i++)
		{
			ParticleSystemBase ps = particleSystems.get(i);
			ps.update(dt);
			if (!ps.getIsAlive())
				deads.add(ps);
		}

		for (int i = 0; i < deads.size(); i++)
			particleSystems.remove(deads.get(i));
	}

	public static void draw(Canvas canvas)
	{ 
		for (int i = 0; i < particleSystems.size(); i++)
		{
			particleSystems.get(i).draw(canvas);
		}
	}
}
